package org.snare.alumni.modules.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.snare.alumni.modules.admin.reservation.dto.ReservationDTO;
import org.snare.alumni.modules.admin.reservation.entity.ReservationEntity;
import org.snare.alumni.modules.admin.reservation.service.api.ReservationService;
import org.snare.spider.common.base.Limit;
import org.snare.spider.common.utils.BeanUtils;
import org.snare.spider.toolkit.jwt.JwtUtils;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "返校预约")
@RequestMapping("/alumni/app/reservation")
@RestController
@RequiredArgsConstructor
public class ReservationController {

    private final ReservationService reservationService;

    @PostMapping("/apply")
    @ApiOperation(value = "申请", httpMethod = "POST")
    void apply(@RequestBody @Valid ReservationDTO params) {
        ReservationEntity entity = BeanUtils.copy(params, ReservationEntity.class);
        entity.setUid(JwtUtils.getUid());
        reservationService.add(entity);
    }

    @GetMapping("/records")
    @ApiOperation(value = "申请记录", httpMethod = "GET")
    IPage<ReservationEntity> records(Limit limit) {
        ReservationEntity reservationEntity = new ReservationEntity();
        reservationEntity.setUid(JwtUtils.getUid());
        return reservationService.page(reservationEntity, limit);
    }

}
